package cn.gok.server.service.impl;

import cn.gok.common.dao.backstage.SysUserMapper;
import cn.gok.common.entity.backstage.Commons;
import cn.gok.common.entity.backstage.SysUser;
import cn.gok.server.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: DxlinY
 * @apiNote: 公共用户服务层
 * @date: 2020/9/25
 * @time: 11:01
 */
@Service("sysUserServiceImpl")
@Slf4j
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String username) {
        log.info("用户{}登录查询", username);
        SysUser sysUser = new SysUser();
        sysUser.setUserName(username);
        Wrapper <SysUser> wrapper = new QueryWrapper <>(sysUser);
        SysUser target = sysUserMapper.selectOne(wrapper);
        if (target != null) {
            log.info("用户{}查询成功", username);
            return target;
        }
        return null;
    }

    @Override
    public String getRoleById(long id) {
        return sysUserMapper.getRoleNameById(id);
    }

    @Override
    public List <String> getPermissionsById(long id) {
        return sysUserMapper.getPermissionsById(id);
    }
}
